import 'package:flutter/material.dart';
import "../pages/TestPage.dart";
import "../pages/TabPage.dart";
import "../pages/TabVPage.dart";
import "../pages/TabNPage.dart";
import '../pages/TestEditForm.dart';
import '../pages/ProfilePage.dart';
import '../pages/request/RequestTest.dart';
import '../pages/game2048/Game2048Home.dart';
import '../pages/TestReadPage.dart';
import '../pages/TestEditPage.dart';
import '../pages/stepper/StepperTest.dart';
import '../pages/stepper/StepperTest2.dart';
import '../pages/stepper/StepperTest3.dart';

import '../pages/request/DoubanTheatersTest.dart';
import '../pages/TestInputText.dart';

import '../plugins/TestImagePicker.dart';

import '../widgets/AppAboutPage.dart';
import '../widgets/misc/DDWebView.dart';
import '../widgets/buttons/ExampleButtons.dart';
import '../widgets/logins/ExampleLogins.dart';
import '../widgets/DDRadioGroupTest.dart';

class RouteUtils {
  static route2Page(BuildContext context, Widget page) {
    Navigator.of(context).push(
          new PageRouteBuilder(
            opaque: false,
            pageBuilder: (BuildContext context, _, __) {
              return page;
            },
            transitionsBuilder:
                (_, Animation<double> animation, __, Widget child) {
              return new FadeTransition(
                opacity: animation,
                child: new FadeTransition(
                  opacity: new Tween<double>(begin: 0.5, end: 1.0)
                      .animate(animation),
                  child: child,
                ),
              );
            },
          ),
        );
  }

  static getFixUrl(String url) {
    String fixUrl = url;

    if (url.startsWith('http')) {
      fixUrl = url.replaceAll('http', 'https');
    }

    return fixUrl;
  }

  ///
  /// 查看图片
  ///
  static void showPhoto(
      BuildContext context, String imageTitle, String imageUrl) {
    Navigator.push(
      context,
      new MaterialPageRoute<void>(
        builder: (BuildContext context) {
          return new Scaffold(
            appBar: new AppBar(
              title: new Text(
                imageTitle,
                overflow: TextOverflow.ellipsis,
              ),
            ),
            body: new SizedBox.expand(
              child: new Hero(
                tag: imageTitle,
                child: Image.network(imageUrl),
              ),
            ),
          );
        },
      ),
    );
  }

  static buildRotes() {
    return <String, WidgetBuilder>{
      // "/main": (BuildContext context) => MainPage(),
      // "/home": (BuildContext context) => HomePage(),
      // "/login": (BuildContext context) => LoginPage(),
      // "/register": (BuildContext context) => RegisterPage(),
      // "/changePassword": (BuildContext context) => ChangePasswordPage(),
      // "/notify": (BuildContext context) => NotifyPage(),
      // "/faq": (BuildContext context) => FaqPage(),
      // "/feedback": (BuildContext context) => FeedbackPage(),
      // "/service": (BuildContext context) => ServicePage(),
      // "/about": (BuildContext context) => AboutPage(),
      // "/lms/listAll": (BuildContext context) => ApplyTabPage(0),
      // "/lms/listTodo": (BuildContext context) => ApplyTabPage(1),
      // "/lms/listUpload": (BuildContext context) => ApplyTabPage(2),
      // "/lms/listApprove": (BuildContext context) => ApplyTabPage(3),
      // "/lms/listScore": (BuildContext context) => ApplyTabPage(4),
      // "/lms/detail": (BuildContext context) => ApplyDetailPage(),
      // "/lms/score": (BuildContext context) => ScorePage(
      //       applyId: 510,
      //     ),
      // "/lms/attchment": (BuildContext context) => ApplyAttachmentPage(
      //       applyId: 510,
      //     ),
      // "/lms/history": (BuildContext context) => ApplyApproveHistory(),
      // "/lms/create": (BuildContext context) => CreateApplyPage(),

      "/test": (BuildContext context) => TestPage(),
      "/test/tab": (BuildContext context) => TabPage(),
      "/test/tabv": (BuildContext context) => TabVPage(),
      "/test/tabn": (BuildContext context) => TabNPage(),
      "/test/editForm": (BuildContext context) => TestEditForm(),
      "/test/profile": (BuildContext context) => ProfilePage(),
      "/test/request": (BuildContext context) => RequestTest(),
      "/test/game2048": (BuildContext context) => Game2048Home(),
      "/test/read": (BuildContext context) => TestReadPage(),
      "/test/edit": (BuildContext context) => TestEditPage(),
      "/test/stepper": (BuildContext context) => StepperTest(),
      "/test/stepper2": (BuildContext context) => StepperTest2(),
      "/test/stepper3": (BuildContext context) => StepperTest3(),
      "/test/imagePicker": (BuildContext context) => TestImagePicker(),
      "/test/douban": (BuildContext context) => DoubanTheatersTest(),
      "/test/input": (BuildContext context) => TestInputText(),

      "/widgets/about": (BuildContext context) => MyAboutTile("贝享金融"),
      "/widgets/webview": (BuildContext context) =>
          DDWebView("我的网站", "http://www.baidu.com"),
      "/widgets/radio": (BuildContext context) => DDRadioGroupTest(),
      "/widgets/button": (BuildContext context) => ExampleButtons(),
      "/widgets/login": (BuildContext context) => ExampleLogins(),
    };
  }
}
